
type Minus<T extends unknown[], U extends unknown[]> = T extends [...U, ...infer R] ? R['length'] : 0

type MyFlatten<T extends any[]> = T extends [infer P, ...infer R]
    ? P extends any[]
        ? [...P, ...MyFlatten<R>]
        : [P, ...MyFlatten<R>]
    : T


type FlattenDepth<T extends any[], D extends number = 1, M = ['-1']> = D extends 0
    ? T
    : Equal<T, M> extends true
        ? T 
        : FlattenDepth<MyFlatten<T>, Minus<BuildArr<D>, BuildArr<1>>, T>

// 最后一个样例过不了